<style>
.pure_form_extra label, .pure_form_extra input { font-size: 12px !important; }
.pure_form_extra label * { font-size: 12px !important; }
.pure_form_extra select { font-size: 12px !important; }
.pure_form_extra .mandatory { color: #ff0000; padding-left: 5px; }
.pure_form_extra { background: #fff; padding: 10px; border: 1px solid #aaa; border-radius: 3px; font-size: 12px !important; }
</style>
<?php if (isset($_SESSION['user'])) { ?>
<?php $user = json_decode($_SESSION['user']); ?>
<table style="width: 100%;" cellpadding=0 cellspacing=0>
  <tr>
    <td id="cs_catbar" style="width: 200px; vertical-align: top; padding-right: 10px;">
      <div id="register" class="pure-form pure-form-aligned pure_form_extra" style="min-height: 70px;">
        <legend>会员中心</legend>
        <label style="paddding-top: 15px;">基本信息</label>
      </div>
    </td>
    <td style="vertical-align: top;">
      <div id="register" class="pure-form pure-form-aligned pure_form_extra">
        <div class="pure-control-group">
          <label>邮箱<span class="mandatory">*</span></label>
          <input id="reg_user" type="text" class="pure-input-1-2" placeholder="{email}" readonly="true" value="<?php echo $user->account; ?>"/>
        </div>
        
        <div class="pure-control-group">
          <label>密码</label>
          <input id="reg_pass" type="password" class="pure-input-1-2" placeholder="{password}" />
        </div>
        
        <div class="pure-control-group">
          <label>姓名<span class="mandatory">*</span></label>
          <input id="reg_last" type="text" placeholder="{family name}" value="<?php echo $user->last_name; ?>"/>
          <input id="reg_first" type="text" placeholder="{given name}" value="<?php echo $user->first_name; ?>"/>
        </div>
        
        <div class="pure-control-group">
          <label>日常居住地<span class="mandatory">*</span></label>
          <select id="living_country" class="pure-input-1-2" onchange="render();">
            <?php foreach ($LIVING_COUNTRIES as $itm) { ?>
            <option <?php if ($itm == $user->living_country) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>&nbsp;</label>
          <select id="living_area" class="pure-input-1-2">
            <?php if ($user->living_country == '中国') { ?>
              <?php foreach ($CN_CITIES as $itm) { ?>
              <option <?php if ($itm == $user->living_area) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
              <?php } ?>
            <?php } else { ?>
              <?php foreach ($NZ_AREAS as $itm) { ?>
              <option <?php if ($itm == $user->living_area) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
              <?php } ?>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>家庭收入<span class="mandatory">*</span></label>
          <select id="family_income" class="pure-input-1-2">
            <?php foreach ($FAMILY_INCOMES as $itm) { ?>
            <option <?php if ($itm == $user->family_income) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>准备购买<span class="mandatory">*</span></label>
          <select id="investment_type" class="pure-input-1-2">
            <?php foreach ($INVEST_TYPES as $itm) { ?>
            <option <?php if ($itm == $user->investment_type) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>目标区域<span class="mandatory">*</span></label>
          <select id="interested_area" class="pure-input-1-2">
            <?php foreach ($NZ_AREAS as $itm) { ?>
            <option <?php if ($itm == $user->interested_area) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>特别中意街道/地区</label>
          <input id="interested_area_de" type="text" class="pure-input-1-2" placeholder="{interested area}" value="<?php echo $user->interested_area_de; ?>"/>
        </div>
        
        <div class="pure-control-group">
          <label>房型<span class="mandatory">*</span></label>
          <select id="property_type" class="pure-input-1-2">
            <?php foreach ($HOUSE_TYPES as $itm) { ?>
            <option <?php if ($itm == $user->property_type) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>卧室数量<span class="mandatory">*</span></label>
          <select id="bedroom_num" class="pure-input-1-2">
            <?php foreach ($BDRM_NUM as $itm) { ?>
            <option <?php if ($itm == $user->bedroom_num) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>价格区间<span class="mandatory">*</span></label>
          <select id="price_range" class="pure-input-1-2">
            <?php foreach ($PRICE_RANGE as $itm) { ?>
            <option <?php if ($itm == $user->price_range) echo 'selected="selected"'; ?>><?php echo $itm; ?></option>
            <?php } ?>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>订阅邮件<span class="mandatory">*</span></label>
          <select id="email_required" class="pure-input-1-2">
            <option>是</option>
            <option <?php if ($user->email_required == 0) echo 'selected="selected"'; ?>>否</option>
          </select>
        </div>
        
        <div class="pure-control-group">
          <label>&nbsp;</label>
          <button class="pure-button pure-input-1-2 pure-button-primary" onclick="submit();">确认</button>
        </div>
      </div>
    </td>
  </tr>
</table>

<div>&nbsp;</div>
<div>&nbsp;</div>
<script type="text/javascript">
  var __requrl = '<?php echo Utils::get_requrl($app_data); ?>';
  var __redmd = '<?php echo addslashes($app_data->sys->redmd); ?>';
  var __sys = '<?php echo addslashes($app_data->sys->php_name); ?>';
  var __id = '<?php echo $app_data->param_id; ?>';
  var __url = '<?php echo ($app_data->param_url == '') ? URL . HOME_DIR . $app_data->sys->php_name . '.php' : $app_data->param_url; ?>';
  var __err = '<?php echo ((isset($_SESSION['login_err'])) ? $_SESSION['login_err'] : ''); ?>';
  var __tried = <?php echo ((isset($_SESSION['tried'])) ? $_SESSION['tried'] : 0); ?>;
  var __cities = JSON.parse('<?php echo addslashes(json_encode($CN_CITIES)); ?>');
  var __areas = JSON.parse('<?php echo addslashes(json_encode($NZ_AREAS)); ?>');
  var __user = JSON.parse('<?php echo addslashes($_SESSION['user']); ?>');

  function render() {
    $('#living_area').empty();
    if ($('#living_country :selected').text() == '中国') {
      arr = __cities;
    } else {
      arr = __areas;
    }
    for (var idx in arr) {
      var itm = arr[idx];
      $('#living_area').append('<option>' + itm + '</option>');
    }
  };
  
  function submit() {
    __user.__password = $('#reg_pass').val();
    __user.first_name = $('#reg_first').val();
    __user.last_name = $('#reg_last').val();
    __user.living_country = $('#living_country :selected').text();
    __user.living_area = $('#living_area :selected').text();
    __user.family_income = $('#family_income :selected').text();
    __user.investment_type = $('#investment_type :selected').text();
    __user.interested_area = $('#interested_area :selected').text();
    __user.interested_area_de = $('#interested_area_de').val();
    __user.property_type = $('#property_type :selected').text();
    __user.bedroom_num = $('#bedroom_num :selected').text();
    __user.price_range = $('#price_range :selected').text();
    __user.email_required = $('#email_required :selected').text() == '是' ? 1 : 0;
        
    Ajax.request(
      __requrl + 'submit',
      'req=' + Utils.encodeURI(JSON.stringify(__user)),
      function(rslt) {
        
      },
      null
    );
  };
</script>
<?php } else { ?>
<div class="pure-form pure-form-aligned pure_form_extra">已登录, 跳转页面...</div>
<script type="text/javascript">
var __url = '<?php echo URL . HOME_DIR . '?i=' . $app_data->__login_id . '&u=' . urlencode(Utils::get_url()); ?>';
if (parent != window) {
  parent.location.href = __url;
} else {
  location.href = __url;
}
</script>
<?php } ?>